package util;

import tlsb.Utils;

public class UtilLoadPerf {
	public static void main(String[] args) throws InterruptedException {
		int ratio = Integer.parseInt(args[0]) * 1000;
		long start = System.currentTimeMillis();
		Utils.init();
		Thread.sleep(1000);
		System.out.println(System.currentTimeMillis() - start);
		String line = null;
		int count = 0;

		start = System.currentTimeMillis();

		int i = 0;
		while (null != (line = Utils.getCurList())) {
			count++;
			long cost = System.currentTimeMillis() - start;
			if (cost % 1000 == 0) {
				System.err.println(count + " ops/s");
			}
			if ((i++) > 100000)
				break;
		}

		while (null != (line = Utils.getCurList())) {
			count++;
			long target = (System.currentTimeMillis() - start) * ratio - count;
			if (target < 0) {
				try {
					Thread.sleep(Math.abs(target) / ratio);
					System.out.println("sleep");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (count > 10000000)
				break;
		}
		Utils.cleanup();
	}
}
